package task

type node struct {
	value interface{}
	prev *node
	next *node
}
type HiQueue struct {
	head *node
	tail *node
	size int
}
func (queue *HiQueue) Size() int {
	return queue.size
}

func NewHiQueue() HiQueue {
	return *new(HiQueue)
}

func (queue *HiQueue) Peek() interface{} {
	if queue.head == nil {
		return nil
	}
	return queue.head.value
}
func (queue *HiQueue) Add(value interface{}) {
	new_node := &node{value, queue.tail, nil}
	if queue.tail == nil {
		queue.head = new_node
		queue.tail = new_node
	} else {
		queue.tail.next = new_node
		queue.tail = new_node
	}
	queue.size++
	new_node = nil
}
func (queue *HiQueue) Take() interface{} {
	if queue.head == nil {
		return nil
	}
	first_node := queue.head
	queue.head = first_node.next
	first_node.next = nil
	var val = first_node.value
	queue.size--
	first_node = nil
	return val
}

func  (queue *HiQueue) Clear() {
	for {
		if (queue.size < 1) {
			break
		}
		first_node := queue.head
		queue.head = first_node.next
		first_node.next = nil
		queue.size--
		first_node = nil
	}
}


